package
{
	import controllers.UserListController;
	
	import models.LocalSetting;
	import models.vo.UserVO;
	
	import org.dexter.DexterFramework;
	import org.dexter.sendDexterEvent;
	
	public class UserListCtrl extends UserListController
	{
		[DexterBinding]
		public var localSetting:LocalSetting;
		public function UserListCtrl()
		{
			super();
		}
		[DexterEvent]
		override public function ServerConnectSuccess():void{
			super.ServerConnectSuccess();
			sendDexterEvent("callJs","userOnline",UserVO.self);
		}
		[DexterEvent]
		public function userOnline(user:UserVO):void{
			if(DexterFramework.getProperty("videoCtrl","publishName") == user.id && !user.isSelf){
				sendDexterEvent("playStream",user.id);
				sendDexterEvent("setVideo",user.id);
			}
			sendDexterEvent("callJs","userOnline",user);
		}
		[DexterEvent]
		public function alreadyOnline(user:UserVO):void{
			userOnline(user);
		}
		[DexterEvent]
		public function userOffline(user:UserVO):void{
			sendDexterEvent("callJs","userOffline",user);
		}
		[DexterExternal]
		public function changeNick(id:String,name:String):void{
			sendDexterEvent("broadcast","changeNick",id,name);
		}
		[DexterEvent]
		public function $changeNick(id:String,name:String):void{
			if(id == UserVO.self.id){
				localSetting.userName = name;
			}
			getUserByID(id).name = name;
			sendDexterEvent("callJs","changeUserName",id,name);
		}
		[DexterExternal]
		public function setUserAsExpert(id:String):void{
			if(getUserByID(id).role != UserVO.ADMIN){
				sendDexterEvent("broadcast","setUserAsExpert",id);
			}
		}
		[DexterEvent]
		public function $setUserAsExpert(id:String):void{
			var user:UserVO = getUserByID(id);
			if(user.role == UserVO.GUEST){
				user.role = UserVO.EXPERT;
				sendDexterEvent("callJs","setUserAsExpert",user);
			}else{
				user.role = UserVO.GUEST;
				sendDexterEvent("callJs","setUserAsGuest",id);
			}
		}
	}
}